//
//  HMUserAccountModel.swift
//  HMVVeibo23
//
//  Created by apple on 17/1/19.
//  Copyright © 2017年 apple. All rights reserved.
//

import UIKit
// 用户信息的模型
class HMUserAccountModel: NSObject, NSCoding {
    /// 用户授权的唯一票据
    var access_token: String?
    /// access_token的生命周期，单位是秒数
    // expires_Date = 当前的日期 + 过期的描述
    var expires_in: Double = 0{
        didSet{
            expires_Date = Date(timeIntervalSinceNow: expires_in)
        }
    }
    /// 授权用户的UID
    var uid: String?
    /// 用户昵称
    var screen_name: String?
    /// 用户头像
    var avatar_large: String?
    /// access_token 过期的日期(会员过期时间为5年 普通用户为3天)
    var expires_Date: Date?
    
    // 解决该错误 fatal error: use of unimplemented initializer 'init()' for class 'HMVVeibo23.HMUserAccountModel'
    override init() {
        super.init()
    }
    
    // 归档
    func encode(with aCoder: NSCoder) {
        self.yy_modelEncode(with: aCoder)
    }
    
    // 解档
    required init?(coder aDecoder: NSCoder) {
        super.init()
        self.yy_modelInit(with: aDecoder)
    }
    
    
    // 重写description
    override var description: String{
        let keys = ["access_token", "expires_Date", "uid", "screen_name", "avatar_large"]
        return dictionaryWithValues(forKeys: keys).description
    }
   
}
